const app = getApp();
var request = require('../../utils/request.js');
Page({
    data: {
        item: {
            fid: '1',
            type: '表白',
            title: '',
            text: '',
            pics: [],
            time: '2021-08-08',
            status: 0
        }
    },
    onLoad: function (e) {
        let fid = e.fid
        this.getFormItem(fid)
    },
    getFormItem(fid) {
        let that = this
        request.GET('/api/list/item?fid=' + fid).then(
            function (res) {
                item = res.data
                item.contact = JSON.parse(item.contact)
                item.pics = item.pics.map((item) => {
                    return app.globalData.baseUrl + item
                })
                item.thumb = item.thumb.map((item) => {
                    return app.globalData.baseUrl + item
                })
                that.setData({
                    item
                })
            }
        )
    },
    agree(e) {
        let that = this
        let fid = e.currentTarget.dataset.fid
        console.log(fid)
        request.POST('/api/list/check', {
            'fid': fid,
            'result': true
        }).then(
            that.setData({
                'item.status': 1
            })
        )
    },
    refuse(e) {
        let that = this
        let fid = e.currentTarget.dataset.fid
        console.log(fid)
        request.POST('/api/list/check', {
            'fid': fid,
            'result': false
        }).then(
            function (res) {
                that.setData({
                    'item.status': -1
                })
            }
        )
    },
    detail(e) {
        let fid = e.currentTarget.dataset.fid
        console.log(fid)
    },
    ViewImage(e) {
        console.log(e.currentTarget.dataset)
        qq.previewImage({
            urls: this.data.item.pics,
        });
    },
})
